<template>
  <div class="layout-container">
    <shopee-row class="row" >
      <shopee-col vertical-align="center" :span="2">
        发布名称:
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.name}}
      </shopee-col>
    </shopee-row>
    <br>
    <shopee-row class="row">
      <shopee-col vertical-align="center" :span="2">
        开始时间:
      </shopee-col>
       <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.createtime}}
      </shopee-col>
    </shopee-row>
    <br>
    <shopee-row class="row" >
      <shopee-col vertical-align="center" :span="2">
        Release Cycle:
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.release_cycle}}
      </shopee-col>
    </shopee-row>
    <br>
     <shopee-row class="row">
      <shopee-col vertical-align="center" :span="2">
        版本号:
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.versions}}
      </shopee-col>
    </shopee-row>
<br>
    <shopee-row class="row">
      <shopee-col vertical-align="center" :span="2">
         发版人:
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.admin}}
      </shopee-col>
    </shopee-row>
<br>
    <shopee-row class="row">
      <shopee-col vertical-align="center" :span="2">
        发版时间:
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.release_date}}
      </shopee-col>
    </shopee-row>
    <br>
    <shopee-row class="row" v-loading="loading">
      <shopee-col vertical-align="center" :span="2">
        发版信息
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
      jira release信息有变更时 <el-link type="primary" @click="refresh_version_info">更新</el-link>
      </shopee-col>
    </shopee-row>

    <br>
    <shopee-row class="row" v-loading="loading">
      <shopee-col vertical-align="center" :span="2">
        task 信息
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
         jira task信息有变更时 <el-link type="primary" @click="refresh_task_info">更新</el-link>
      </shopee-col>
    </shopee-row>
    <br>

    <shopee-row class="row" v-loading="loading">
      <shopee-col vertical-align="center" :span="2">
        部署信息
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
         项目 git 配置信息有变更时 <el-link type="primary" @click="refresh_deploy_info">更新</el-link>
      </shopee-col>
    </shopee-row>

    <br>
    <shopee-row class="row">
      <shopee-col vertical-align="center" :span="2">
        任务实例状态:
      </shopee-col>
      <shopee-col vertical-align="center" :span="10">
        {{taskInstanceInfo.status}}
      </shopee-col>
    </shopee-row>
  </div>
</template>

  <script>
    import {api, getRequest, postRequest} from "@/api/commit";
    import {Message} from "element-ui";
    export default {
      name : "TaskInstanceDetailInfo",
      data() {
        return {
          taskInstanceInfo: {},
          loading:false
        }
      },
      methods: {
        refresh_version_info(){
          this.loading=true
          getRequest(api['task_instance_refresh_version_info'],{id:this.$route.query.id}).then((res) => {
            res = res.resultReturn
            if(res.status===1){
                Message({
                  showClose: true,
                  message: res.message,
                  type: "success",
                  duration: 3000
                });
                location.reload()
            }else if (res.status===2){
              Message({
                  showClose: true,
                  message: res.message,
                  type: "error",
                  duration: 3000
                });
            }else if (res.status===3){
              Message({
                  showClose: true,
                  message: res.message,
                  type: "warning",
                  duration: 3000
                });
            }
            this.loading=false
          }, (error) => {
            this.loading=false
            console.info(error)
          })
        },
        refresh_deploy_info(){
           this.loading=true
          getRequest(api['task_instance_refresh_deploy_info'],{id:this.$route.query.id}).then((res) => {
            res = res.resultReturn
            if(res.status===1){
                Message({
                  showClose: true,
                  message: res.message,
                  type: "success",
                  duration: 3000
                });
                location.reload()
            }else if (res.status===2){
              Message({
                  showClose: true,
                  message: res.message,
                  type: "error",
                  duration: 3000
                });
            }else if (res.status===3){
              Message({
                  showClose: true,
                  message: res.message,
                  type: "warning",
                  duration: 3000
                });
            }
            this.loading=false
          }, (error) => {
            this.loading=false
            console.info(error)
          })
        },
        refresh_task_info(){
          this.loading=true
          getRequest(api['task_instance_refresh_task_info'],{id:this.$route.query.id}).then((res) => {
            res = res.resultReturn
            if(res.status===1){
                Message({
                  showClose: true,
                  message: res.message,
                  type: "success",
                  duration: 3000
                });
                location.reload()
            }else if (res.status===2){
              Message({
                  showClose: true,
                  message: res.message,
                  type: "error",
                  duration: 3000
                });
            }else if (res.status===3){
              Message({
                  showClose: true,
                  message: res.message,
                  type: "warning",
                  duration: 3000
                });
            }
            this.loading=false
          }, (error) => {
            this.loading=false
            console.info(error)
          })
        },
        init_data() {
          let params ={
            "id": this.$route.query.id
          }
          getRequest(api['task_instance_view'],params).then((res) => {
            res = res.resultReturn
            this.taskInstanceInfo= res.data
          }, (error) => {
            console.info(error)
          })
        }
      },
      mounted () {
        this.init_data()
      }
    }
  </script>
